home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / gedit-2 / plugins / pythonconsole / __init__.py next >
Encoding:
Python Source  |  2009-04-14  |  2.4 KB  |  72 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. # __init__.py -- plugin object
  4. #
  5. # Copyright (C) 2006 - Steve Fr√©cinaux
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  
  20. # Parts from "Interactive Python-GTK Console" (stolen from epiphany's console.py)
  21. #     Copyright (C), 1998 James Henstridge <james@daa.com.au>
  22. #     Copyright (C), 2005 Adam Hooper <adamh@densi.com>
  23. # Bits from gedit Python Console Plugin
  24. #     Copyrignt (C), 2005 Rapha√´l Slinckx
  25.  
  26. import gtk
  27. import gedit
  28.  
  29. from console import PythonConsole
  30. from config import PythonConsoleConfigDialog
  31.  
  32. class PythonConsolePlugin(gedit.Plugin):
  33.     def __init__(self):
  34.         gedit.Plugin.__init__(self)
  35.         self.dlg = None
  36.         
  37.     def activate(self, window):
  38.         console = PythonConsole(namespace = {'__builtins__' : __builtins__,
  39.                                              'gedit' : gedit,
  40.                                              'window' : window})
  41.         console.eval('print "You can access the main window through ' \
  42.                      '\'window\' :\\n%s" % window', False)
  43.         bottom = window.get_bottom_panel()
  44.         image = gtk.Image()
  45.         image.set_from_icon_name('gnome-mime-text-x-python',
  46.                                  gtk.ICON_SIZE_MENU)
  47.         bottom.add_item(console, _('Python Console'), image)
  48.         window.set_data('PythonConsolePluginInfo', console)
  49.  
  50.     def deactivate(self, window):
  51.         console = window.get_data("PythonConsolePluginInfo")
  52.         console.stop()
  53.         window.set_data("PythonConsolePluginInfo", None)
  54.         bottom = window.get_bottom_panel()
  55.         bottom.remove_item(console)
  56.  
  57.     def is_configurable(self):
  58.         return True
  59.  
  60.     def create_configure_dialog(self):
  61.         if not self.dlg:
  62.             self.dlg = PythonConsoleConfigDialog(self.get_data_dir())
  63.         
  64.         dialog = self.dlg.dialog()
  65.         window = gedit.app_get_default().get_active_window()
  66.         if window:
  67.             dialog.set_transient_for(window)
  68.  
  69.         return dialog
  70.  
  71.